﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Course.Entity;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.User.Entity;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Web.Paper;
using PowerCreator.LMS.Paper.Entiry;
using PowerCreator.LMS.Web.Config;
using PowerCreator.LMS.Web.Project;
using PowerCreator.LMS.Project.Entity;
using PowerCreator.LMS.Task.Entity;
using PowerCreator.LMS.Web.Task;

public partial class Theme_3_ChannelTaskCommet : PowerCreator.LMS.Web.Base.BasePage
{
    protected string fileUrl = string.Empty;
    protected string url = string.Empty;
    protected string _ChannelID = "0";
    protected string _urltype = string.Empty;
    protected string _ChannelName = string.Empty;
    protected string _Author = string.Empty;
    protected string _Description = string.Empty;
    protected string _Title = string.Empty;
    protected string _contentID = string.Empty;

    //protected string _uid = "0";
    protected string _ServerIP = "";
    //protected string _TaskID = "0";
    //protected string _TaskClassID = "0";

    protected string taskCommentUrl = string.Empty;
    protected string AddTaskCommentUrl = string.Empty;
    protected string strGrade = "<a href=\"#\" onclick=\"checkGrade({0})\">{1}</a>";



    //const string SEARCH_GETSUMSCORE = "select Sum(SkillTypeScore) as SumScore from TSkillType";

    const string IMG_OK = "<img src=\"images/x1.jpg\" width=\"16\" height=\"12\" />";
    const string IMG_NO = "<img src=\"images/x2.jpg\" width=\"16\" height=\"12\" />";

    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();

    PowerCreator.LMS.ViewQuery.ViewQuery objViewQuery = new PowerCreator.LMS.ViewQuery.ViewQuery();
    PowerCreator.LMS.Web.Grade.GradeManager op = new PowerCreator.LMS.Web.Grade.GradeManager();
    TaskCommentManag objTaskCommentManag = new TaskCommentManag();
    TaskManag objTaskManag = new TaskManag();
    EvaluateManag objEvaluateManag = new EvaluateManag();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
        {
            Script.Alert(config.GetLanagerValueByKey("theme_Channel_LoginMsg", PowerCreator.LMS.Language.LanagetItemType.Page));
            Script.CloseMe();
        }
        if (!IsPostBack)
        {
            this.Title = config.GetLanagerValueByKey("theme_ChannelComment_TitleInfo", PowerCreator.LMS.Language.LanagetItemType.Page);
            _urltype = Request.QueryString["urltype"].ToString();
            ViewState["urltype"] = _urltype;
            _contentID = Request.QueryString["ContentID"].ToString();
            ViewState["ContentID"] = _contentID;
            _ChannelID = Request.QueryString["ChannelID"].ToString();
            ViewState["ChannelID"] = _ChannelID;
            _ServerIP = Request.QueryString["ServerIP"].ToString();
            Session["ServerIP"] = _ServerIP;
            if (Request.QueryString["ChannelName"] != null)
            {
                _ChannelName = Request.QueryString["ChannelName"].ToString();
                ViewState["ChannelName"] = _ChannelName;
                _Author = Request.QueryString["Author"].ToString();
                ViewState["Author"] = _Author;
                _Description = Request.QueryString["Description"].ToString();
                ViewState["Description"] = _Description;
                _Title = Request.QueryString["Title"].ToString();
                ViewState["Title"] = _Title;

                string[] parameterList = _Description.Split('$');
                ViewState["TaskID"] = parameterList[0].ToString();
                ViewState["TaskClassID"] = parameterList[1].ToString();
                ViewState["TaskUserID"] = parameterList[2].ToString();

                taskCommentUrl = string.Format("TaskID={0}&TaskClassID={1}&TaskUserID={2}&ResourceID=0&ContentID={3}", ViewState["TaskID"].ToString(), ViewState["TaskClassID"].ToString(), ViewState["TaskUserID"].ToString(), ViewState["ContentID"].ToString());
                AddTaskCommentUrl = string.Format("&TaskID={0}&TaskClassID={1}&TaskUserID={2}&ContentID={3}", ViewState["TaskID"].ToString(), ViewState["TaskClassID"].ToString(), ViewState["TaskUserID"].ToString(), ViewState["ContentID"].ToString());

            }

            BinderUserLogin();
            btn_out.Text = config.GetLanagerValueByKey("SignOut", PowerCreator.LMS.Language.LanagetItemType.WebTitle);

            pageload();


            BinderPG(_urltype);




        }
    }

    protected void lnkbtn_EN_Click(object sender, EventArgs e)
    {
        Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_LANGEID] = "1";
    }
    protected void lnkbtn_CN_Click(object sender, EventArgs e)
    {
        Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_LANGEID] = "0";
    }
    protected void BinderUserLogin()
    {
        if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
        {
            lal_UserLogin.Text = "<a  href=\"UserLogin.aspx\">" + config.GetLanagerValueByKey("SysManagerLogin", PowerCreator.LMS.Language.LanagetItemType.Page) + "</a> |  <a  href=\"Register.aspx\">" + config.GetLanagerValueByKey("SysManagerRegistor", PowerCreator.LMS.Language.LanagetItemType.Page) + "</a>";
            btn_out.Visible = false;
        }
        else
        {
            PowerCreator.LMS.Web.User.LoginEntity login = (PowerCreator.LMS.Web.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];
            lal_UserLogin.Text = login.AccountInfo.RealName.Trim() + "," + config.GetLanagerValueByKey("Login_msg_code5", PowerCreator.LMS.Language.LanagetItemType.Page) + "！| ";
            btn_out.Visible = true;
        }
    }
    protected void btn_out_Click(object sender, EventArgs e)
    {
        PowerCreator.LMS.Web.User.User opUser = new PowerCreator.LMS.Web.User.User();
        //opUser.UpdateOnlineUserByUserID(GetLoginEntity.UserID);
        Session.Abandon();
        PowerCreator.LMS.Common.Script.Script.ReloadMe();
    }


    private void pageload()
    {


        int userNum = 0;        //评价总人数
        int ScoreNum = 0;         //评价总分数
        int SumScore = 0;       //量表的总分数
        DataTable dtTaskComment = new DataTable();

        string searchTaskComment = string.Format(" TaskCtTaskID={0} and TaskCtTaskClassID={1} and TaskCtUserID={2} and FKTaskCtResourceGuid='{3}' and TaskCtType=4 ", ViewState["TaskID"].ToString(), ViewState["TaskClassID"].ToString(), ViewState["TaskUserID"].ToString(), ViewState["ContentID"].ToString());
        dtTaskComment = objTaskCommentManag.Query(searchTaskComment);

        for (int i = 0; i < dtTaskComment.Rows.Count; i++)
        {
            int score = int.Parse(dtTaskComment.Rows[i]["TaskCtScore"].ToString());
            ScoreNum += score;
        }

        userNum = dtTaskComment.Rows.Count;
        if (userNum > 0)
        {
            lab_AvgScore.Text = Convert.ToString(ScoreNum / userNum);

        }
        else
        {
            lab_AvgScore.Text = "0";
        }

        VOTask objVOTask = objTaskManag.Load(int.Parse(ViewState["TaskID"].ToString()));
        ViewState["EvateID"] = objVOTask.FKTaskEvaluateID;
        ViewState["TaskAppraiseType"] = objVOTask.TaskAppraiseType;
        SumScore = objEvaluateManag.Load(objVOTask.FKTaskEvaluateID).EvateScore;


        string str_Star = "";
        if (objVOTask.TaskAppraiseType == 2)//量表评价
        {


            strGrade = string.Format(strGrade, "target", GetLanageValueByKey("theme_Comment_AddComment", PowerCreator.LMS.Language.LanagetItemType.Page));

            double result = Convert.ToDouble(lab_AvgScore.Text) / SumScore;
            int countStart = Convert.ToInt32(result * 10);

            for (int i = 0; i < 10; i++)
            {

                if (i < countStart)
                {
                    str_Star += IMG_OK;
                }
                else
                {
                    str_Star += IMG_NO;
                }


            }
        }
        else//直接打分
        {

            strGrade = string.Format(strGrade, "mark", GetLanageValueByKey("theme_Comment_AddComment", PowerCreator.LMS.Language.LanagetItemType.Page));

            int countStart = 7;//暂时设定为7颗星
            for (int i = 0; i < 10; i++)
            {

                if (i < countStart)
                {
                    str_Star += IMG_OK;
                }
                else
                {
                    str_Star += IMG_NO;
                }


            }

        }
        lab_Star.Text = str_Star;
    }

    private void BinderPG(string type)
    {

        //urltype=all&ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&Title=" + dt.Rows[i]["Title"].ToString() + "&Author=" + dt.Rows[i]["Author"].ToString() + "&Description=" + dt.Rows[i]["Description"].ToString()
        if (type == "leftup")
        {
            fileUrl = "../../web/broadcast/frmleftup.aspx?ChannelID=" + _ChannelID + "&ChannelName=" + _ChannelName + "&Title=" + _Title + "&Author=" + _Author + "&Description=" + _Description + "&type=Vedio" + "&ServerIP=" + _ServerIP;
        }
        else if (type == "right")
        {
            fileUrl = "../../web/broadcast/frm000.aspx?ChannelID=" + _ChannelID + "&ChannelName=" + _ChannelName + "&Title=" + _Title + "&Author=" + _Author + "&Description=" + _Description + "" + "&ServerIP=" + _ServerIP;
        }
        else if (type == "all")
        {
            fileUrl = "../../web/broadcast/Content.aspx?ChannelID=" + _ChannelID + "&ChannelName=" + _ChannelName + "&Title=" + _Title + "&Author=" + _Author + "&Description=" + _Description + "" + "&ServerIP=" + _ServerIP;
        }
        else if (type == "dual")
        {
            fileUrl = "../../web/broadcast/dual/Content.aspx?ChannelID=" + _ChannelID + "&ChannelName=" + _ChannelName + "&Title=" + _Title + "&Author=" + _Author + "&Description=" + _Description + "" + "&ServerIP=" + _ServerIP;
        }

        //绑定主评论信息
        //BinderComment();
    }
 
    protected void btn_send_ServerClick(object sender, EventArgs e)
    {

    }


}
